<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增')" />
    <script type="text/javascript" src="/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="/js/jutils.min.js"></script>
    <script type="text/javascript" src="/js/simple-calendar.js"></script>
    <link rel="stylesheet" href="/css/simple-calendar.css" />
    <th:block th:include="include :: datetimepicker-css" />
    <object  id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
        <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0/>
    </object>
    <script type="text/javascript" src="/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="/js/LodopFuncs.js"></script>
    <script type="text/javascript" src="/js/printSmall.js"></script>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-orderhead-add" style="z-index: 0">
            <div class="form-group">    
                <label class="col-sm-3 control-label ">客户名称：</label>
                <div class="col-sm-8">
                    <input name="clientName" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">联系电话：</label>
                <div class="col-sm-8">
                    <input name="phoneOne" class="form-control" type="text" onblur="checkPhone(this)" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">紧急电话：</label>
                <div class="col-sm-8">
                    <input name="phoneTwo" class="form-control" type="text" onblur="checkPhone(this)">
                </div>
            </div>
            <div class="form-group container" >
                <label class="col-sm-3 control-label is-required">所在城市:</label>
                <select id="shi"  class="btn btn-default dropdown-toggle" style="margin-left:12px " onblur="zhenUpdate()" >
                    <option value="" >所有</option>
                </select>
                <select id="zhen" class="btn btn-default dropdown-toggle" style="margin-left:12px "  name="regionClient" >
                    <option value="">所有</option>
                </select>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">详细地址：</label>
                <div class="col-sm-8">
                    <textarea name="address" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">订金：</label>
                <div class="col-sm-8">
                    <input name="depositOrderHead" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">添加商品：</label>
                <div class="col-sm-8">
                    <table class="table" id="tProduct">
                        <tr>
                            <th>商品名称</th>
                            <th>商品单价</th>
                            <th>数量</th>
                        </tr>
                        <tr id="pirceTr">
                            <td><select name="productIDOrder" class="form-control m-b" th:with="type=${@product.queryProductList()}" onchange="addGoods(this.options[this.options.selectedIndex],this)" required>
                                <option value="">-&#45;&#45;请选择-&#45;&#45;</option>
                                <option th:each="dict : ${type}" th:text="${dict.nameProduct}" th:value="${dict.idProduct}"></option>
                            </select></td>
                            <td><input id="price" name="price" class="form-control" type="text" required></td>
                            <td><input name="countOrders" class="form-control" type="text" required></td>
                            <td><input type="button" class="btn-sussess" onclick="addProduct()" value="继续添加"></input></td>
                        </tr>
                    </table>
                </div>
            </div>
           <!-- <div class="form-group" id="p">
                <label class="col-sm-3 control-label is-required" >选择商品：</label>
                <div class="col-sm-8" style="width: 280px;">
                    <select name="listClass" class="form-control m-b" th:with="type=${@product.queryProductList()}" onchange="addGoods(this.options[this.options.selectedIndex])" required>
                        <option value="">-&#45;&#45;请选择-&#45;&#45;</option>
                        <option th:each="dict : ${type}" th:text="${dict.nameProduct}" th:value="${dict.idProduct}"></option>
                    </select>
                </div>
                <div class="col-sm-8" style="display: -webkit-box; width: 80px; padding-left: 0px;">
                    <span style="line-height: 2.5;">数量：</span>
                    <input name="depositOrderHead" class="form-control" type="text">
                </div>
                <div class="col-sm-8" style="display: -webkit-box; width: 110px; padding-left: 30px;">
                    <span style="line-height: 2.5;">商品单价：</span>
                    <input id="price" name="price" class="form-control" type="text">
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">交货日期：</label>
                <div class="col-sm-8">
                    <div class="form-group">
                        <!--<input name="appointmentDateOrderHead" class="form-control" placeholder="yyyy-MM-dd" type="text" required>-->
                        <div  onclick="showDate()" >
                            <input id="nlDate" style="pointer-events : none;"  name="appointmentDateOrderHead" class="form-control"  type="date" value="" placeholder="yyyy-MM-dd"  required>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="commentOrderHead" class="form-control"></textarea>
                </div>
            </div>
        </form>
        <div id="container" style="position: absolute; visibility: hidden;z-index: 1000;" onclick="getDate()"  ></div>
       <!-- <button id="querd" class="datebutton btn btn-default" onclick="getDate()" style="position: absolute; visibility: hidden">确定</button>-->
        <button id="channel" class="datebutton btn btn-success"  onclick="channel()" style="position: absolute;  visibility: hidden">取消</button>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        $(function(){
            $("#nlDate").click(function (event) {
                event.preventDefault();
            })
        })
        var myCalendar = new SimpleCalendar('#container');
        if (/(Android)/i.test(navigator.userAgent)) {
            myCalendar.updateSize('230px', '300px');
            $("#container").css("font-size","10px");
            $("#container").css("left","25%");
            $("#container").css("top","20%");
            $("#channel").css("left","65%");
            $("#channel").css("top","75%");
            $("#querd").css("left","50%");
            $("#querd").css("top","75%");
        } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
            myCalendar.updateSize('230px', '300px');
            $("#container").css("font-size","10px");
            $("#container").css("left","25%");
            $("#container").css("top","20%");
            $("#channel").css("left","65%");
            $("#channel").css("top","75%");
            $("#querd").css("left","50%");
            $("#querd").css("top","75%");
        } else {
            myCalendar.updateSize('300px', '350px');
            $("#container").css("font-size","15px");
            $("#container").css("left","30%");
            $("#container").css("top","10%");
            $("#channel").css("left","65%");
            $("#channel").css("top","100%");
            $("#querd").css("left","57%");
            $("#querd").css("top","100%");
        }

        function showDate(){
            $("#container").css("visibility","visible");
            $(".datebutton").css("visibility","visible");
        }
        function getDate(){
            let date = myCalendar.getSelectedDay();
            console.log(date);

            date =jutils.formatDate(date,"YYYY-MM-DD");
            $("#nlDate").val(date);
            $("#container").css("visibility","hidden");
            $(".datebutton").css("visibility","hidden");
        }
        function channel(){
            $("#container").css("visibility","hidden");
            $(".datebutton").css("visibility","hidden");
        }

        var prefix = ctx + "system/orderhead"
        $("#form-orderhead-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                save(prefix + "/add", $('#form-orderhead-add').serialize(),printSmall);

            }
        }
        function printSmall(orderid){
            p(orderid);
        }
        // 保存信息 刷新表格
        function save(url, data, callback) {
            var config = {
                url: url,
                type: "post",
                dataType: "json",
                data: data,
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function(result) {
                    if (typeof callback == "function") {
                        console.log("---------"+result.msg)
                        callback(result.msg);
                    }
                    $.operate.successCallback(result);
                }
            };
            $.ajax(config)
        }
        $("input[name='dateOrderHead']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='appointmentDateOrderHead']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        $(function(){
            $("#shi").html("");
            let url = "/system/region/listById";
            let param = {"parentId":27425};
            $.getJSON(url,param,function(json){
                let rows = json.rows;
                $(rows).each(function(i,item){
                    let html = '';
                    html += '<option value='+item.idRegion+'>'+item.nameRegion+'</option>';
                    $("#shi").append(html);
                })
            })
        })
        function zhenUpdate(){
            $("#zhen").html("");
            let url = "/system/region/listById";
            let parentId = $("#shi").val();
            let param = {"parentId":parentId};
            $.getJSON(url,param,function(json){
                let rows = json.rows;
                $(rows).each(function(i,item){
                    let html = '';
                    html += '<option value='+item.idRegion+'>'+item.nameRegion+'</option>';
                    $("#zhen").append(html);
                })
            })
        }

        function checkPhone(obj) {
            console.log(obj);
            var re = /^1([23578])\d{9}$/;
            console.log(obj.value);
            if (!re.test(obj.value)) {
                alert("请输入正确的电话号码!");
                obj.value = "";
            }
        }

        /*function loadGoods() {
            $("#goods").html("");
            let url = "/system/product/getGoods";
            $.getJSON(url,null,function(json){
                let rows = json.rows;
                $(rows).each(function(i,item){
                    let html = '';
                    html += '<option value='+item.idProduct+'>'+item.nameProduct+'</option>';
                    $("#goods").append(html);
                })
            })
        }*/
        var i = 0;
        function addProduct(){
            i++;
            let oldTr=$("#pirceTr").html();
            let tr = $("<tr></tr>");
            tr.html(oldTr)
            $($(tr.children()[1]).children()[0]).attr("id","price"+i);
            console.log(oldTr);
            $("#tProduct").append(tr);
        }

        function addGoods(val,that) {
            //赋值
            let url = "/system/product/getPrice";
            let idProduct = val.value;
            console.log(idProduct)
            let param = {"idProduct": idProduct};
            $.getJSON(url, param, function (json) {
                $($(that).parent().next().children()[0]).val(json.data)
            })
        }


    </script>
</body>
</html>